package logic

import (
	"context"
	"zy31/rpc/model/mysql"

	"zy31/rpc/internal/svc"
	"zy31/rpc/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *user.OrderListRequest) (*user.OrderListResponse, error) {
	var order []mysql.Order
	mysql.DB.Find(&order)
	var list []*user.OrderList
	for _, m := range order {
		orderList := user.OrderList{
			UserId:     int64(m.UserId),
			GoodsId:    int64(m.GoodsId),
			OrderSn:    m.OrderSn,
			OrderPrice: float32(m.OrderPrice),
			PayStatus:  int64(m.PayStatus),
			Payment:    int64(m.Payment),
			GoodsName:  m.GoodsName,
			GoodsImg:   m.GoodsImg,
		}
		list = append(list, &orderList)
	}
	return &user.OrderListResponse{
		List: list,
	}, nil
}
